import 'package:flutter_admin/pages/common/cry/cry_all.dart';
import 'package:flutter_admin/pages/common/cry/vo/select_option_vo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_admin/pages/common/cry/cry_button.dart';
import 'package:flutter_admin/api/odoo/dynamic_data_api.dart';
import 'package:flutter_admin/models/odoo/sale_bid_project.dart';
import '../../../generated/l10n.dart';

class SaleBidProjectDialog extends StatefulWidget {
  SaleBidProjectDialog();

  @override
  _SaleBidProjectDialogState createState() => _SaleBidProjectDialogState();
}

class _SaleBidProjectDialogState extends State<SaleBidProjectDialog> {

  // late List<Widget> children;
  final GlobalKey<FormState> formKey = GlobalKey<FormState>();

  SaleBidProject  saleBidProject = SaleBidProject();

   //项目类别(0：市场部，1：海外部，2：其他)
  List<SelectOptionVO> projectcategoryList = [];

  @override
  void initState() {
    super.initState();
    _loadData();
  }

  _loadData() async{
    //项目类别(0：市场部，1：海外部，2：其他)
    projectcategoryList = await DynamicDataApi.getDictList("projectcategory");
    setState(() { });
  }
  @override
  Widget build(BuildContext context) {
    var form = Form(
      key: formKey,
      child: Wrap(
        children: <Widget>[
          CrySelect(
            label: '项目类别(0：市场部，1：海外部，2：其他)',
            dataList: projectcategoryList,
            value: saleBidProject.projectcategory,
            onSaved: (v) => { saleBidProject.projectcategory = v},
          ),
          CryInput(
            width: 400,
            label: '项目编号',
            value: saleBidProject.projectcode,
            onSaved: (v) {
              saleBidProject.projectcode = v;
            },
          ),
          CryInput(
            width: 400,
            label: '项目名称',
            value: saleBidProject.projectname,
            onSaved: (v) {
              saleBidProject.projectname = v;
            },
          ),

        ],
      ),
    );
    var buttonBar = ButtonBar(
      alignment: MainAxisAlignment.center,
      children: <Widget>[
        CryButton(
          label: "确定",
          onPressed: () {
            FormState form = formKey.currentState!;
            form.save();
            Navigator.pop(context, saleBidProject);
          },
          iconData: Icons.save,
        ),
        CryButton(
          label: S.of(context).cancel,
          onPressed: () {
            Navigator.pop(context);
          },
          iconData: Icons.cancel,
        )
      ],
    );
    var result = Scaffold(
      appBar: AppBar(
        title: Text("查询"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [form],
        ),
      ),
      bottomNavigationBar: buttonBar,
    );
    return SizedBox(
      width: 650,
      height: 650,
      child: result,
    );
    // return result;
  }
}